<template>
  <a-modal :open="open" width="640px" title="新增配血结果" centered :keyboard="false" @ok="onOk" @cancel="onCancel">
    <a-form :model="formState" :colon="false">
      <a-form-item label="是否合格" class="w-full">
        <a-switch v-model:checked="formState.isPass" />
      </a-form-item>
      <a-form-item label="配血结果" class="w-full">
        <a-textarea v-model:value="formState.matchResult" :rows="6" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

defineProps({
  open: Boolean
})

const emit = defineEmits(['update:open', 'success'])
const formState = ref({})

const onOk = async () => {
  const res = await post('/bloodm/BldTransfusionRecord/doSaveBldTransfusionResult', { ...formState.value, isPass: formState.value.isPass ? 1 : 0 })
  res.code !== 0 ? message.error(res.msg || '操作失败') : message.success('保存成功')
  onCancel()
  emit('success')
  formState.value = {}
}
const onCancel = () => {
  emit('update:open', false)
}
</script>
